<template>
	<view class="testdriveresult">
		<image v-if="test_drive_img" class="testdrive_bk_img" :src="picUrl+test_drive_img" mode="widthFix"></image>
		<view class="testdrive_result_box">
			<view class="ticket_userinfo_box">
				<view class="ticket_userinfo_cell">
					<view class="c-gray">姓名</view>
					<view class="">{{info.name}}</view>
				</view>
				<view class="ticket_userinfo_cell">
					<view class="c-gray">电话</view>
					<view class="">{{info.mobile}}</view>
				</view>
				<view class="ticket_userinfo_cell" v-if="info.channel=='zh'">
					<view class="c-gray">粉丝嘉年华现场试乘预约</view>
					<view class="">{{info.project_name}}</view>
				</view>
				<view class="ticket_userinfo_cell">
					<view class="c-gray">试驾车型</view>
					<view class="">{{info.drive_car_series}}</view>
				</view>
				<view class="ticket_userinfo_cell">
					<view class="c-gray">试驾经销商</view>
					<view class="">{{info.company_info}}</view>
				</view>
				<view class="ticket_userinfo_cell">
					<view class="c-gray">预约时间</view>
					<view class="">{{info.create_time}}</view>
				</view>
				<view class="ticket_userinfo_cell" v-if="info.sign_status==1">
					<view class="c-gray">试驾时间</view>
					<view class="">{{info.sign_time}}</view>
				</view>
				<view class="ticket_userinfo_cell" v-if="info.sign_status==2">
					<view class="c-gray">取消时间</view>
					<view class="">{{info.sign_time}}</view>
				</view>
				<view class="ticket_userinfo_cell">
					<view class="c-gray">试驾状态</view>
					<view v-if="info.sign_status==0" class="c-red">未试驾</view>
					<view v-if="info.sign_status==1" class="c-green">已试驾</view>
					<view v-if="info.sign_status==2" class="c-gray">已取消</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getClubConfig,
		getDriverInfo,
		cancelDrive
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				info: '',
				channel: 0,
				test_drive_img: '',
				picUrl: app.globalData.picUrl,
				onlinePic: app.globalData.onlinePic,
			};
		},
		onShow() {
			if (!uni.getStorageSync('access_token')) {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}
		},
		onLoad(options) {
			this.id = options.drive_id
			this.channel = options.channel ? options.channel : 0
			if (uni.getStorageSync('clubconfig')) {
				this.test_drive_img = uni.getStorageSync('clubconfig').test_drive_img
				this.test_drive_car_series_arr = uni.getStorageSync('clubconfig').test_drive_car_series_arr
			} else {
				this.getClubConfig()
			}
			this.getDriverInfo()
		},
		methods: {
			getDriverInfo() {
				getDriverInfo({
					id: this.id,
					channel: this.channel
				}).then(res => {
					if (res.state == 1) {
						this.info = res.data.info
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			getClubConfig() {
				getClubConfig({}).then(res => {
					if (res.state == 1) {
						uni.setStorage({
							key: 'clubconfig',
							data: res.data,
							success: function() {}
						});
						this.test_drive_img = res.data.test_drive_img
						this.test_drive_car_series_arr = res.data.test_drive_car_series_arr
					} else {}
				})
			},
			cancelDrive() {
				cancelDrive({
					id: this.id
				}).then(res => {
					if (res.state == 1) {
						uni.showToast({
							title: '成功',
							mask: true,
							icon: 'success',
							duration: 1500
						})
						uni.setStorage({
							key: 'onload',
							data: true
						})
						this.getDriverInfo()
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			}
		},
		onShareAppMessage(res) {
			return {

			}
		},
		onShareTimeline: function() {
			return {

			}
		},
	}
</script>

<style lang="scss">
	.testdriveresult {
		.testdrive_bk_img {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			z-index: -1;
		}

		.testdrive_result_box {
			margin: 0 30rpx;
			margin-top: 65%;
			padding-top: 40rpx;
			background-color: #ffffff;

			.code_img_box {
				margin-top: 35rpx;
				text-align: center;

				.code_img {
					width: 190rpx;
					height: 190rpx;
				}

				.code_img_def {
					width: 190rpx;
					height: 190rpx;
					filter: grayscale(100%);
				}
			}

			.ticket_userinfo_box {
				margin: 50rpx 30rpx 0 30rpx;
				// border-top: 1rpx dotted #AEAEAE;

				.ticket_userinfo_cell {
					font-size: 28rpx;
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
				}
			}
		}

	}
</style>